<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>向我的第一个项目致敬</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap.min.css') }}">
    <script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
    <script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
</head>
<body>
<div style="padding:30px;">
    <div class="container" style="margin-top: 200px; width: 600px;">
        <div class="jumbotron">
            <form class="form-horizontal">
                <div class="form-group">
                    <label for="username" class="col-sm-2 control-label">username</label>
                    <div class="col-sm-10">
                        <input type="email" class="form-control" id="username" placeholder="username">
                    </div>
                </div>
                <div class="form-group">
                    <label for="password" class="col-sm-2 control-label">Password</label>
                    <div class="col-sm-10">
                        <input type="password" class="form-control" id="password" placeholder="password">
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-10">
                        <p class="help-block" id="message_tip"></p>
                        <button type="button" class="btn btn-default" id="loginBtn">登录</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <script>
        // 获取银行卡号
        $('#loginBtn').click(function () {

            $('#message_tip').text('');

            let username = $('#username').val();
            let password = $('#password').val();
            if (!!!username) {
                $('#message_tip').text('请输入用户名');
                return;
            }

            if (!!!password) {
                $('#message_tip').text('请输入密码');
                return;
            }


            $.ajax({
                url: '/login',
                type: 'POST',
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify({"username": username, "password": password}),
                dataType: "json",
                success: function (data) {
                    if (data.status === 1) {
                        location = '/app/index'
                    } else {
                        $('#message_tip').text(data.message);
                    }
                }
            })
        });
    </script>
</div>
</body>
</html>